#include <block.h>
Public Member Functions | |
Block (int size, void(*err_function)(char *)=NULL) | |
~Block () | |
Type * | New (int num=1) |
Type * | ScanFirst () |
Type * | ScanNext () |
void | Reset () |
Private Types | |
typedef Block::block_st | block |
Private Attributes | |
int | block_size |
block * | first |
block * | last |
block * | scan_current_block |
Type * | scan_current_data |
void(* | error_function )(char *) |
Classes | |
struct | block_st |
Definition at line 99 of file block.h.
typedef struct Block::block_st Block< Type >::block [private] |
Block< Type >::Block | ( | int | size, | |
void(*)(char *) | err_function = NULL | |||
) | [inline] |
Definition at line 106 of file block.h.
00106 { first = last = NULL; block_size = size; error_function = err_function; }
Type* Block< Type >::New | ( | int | num = 1 |
) | [inline] |
Definition at line 114 of file block.h.
00115 { 00116 Type *t; 00117 00118 if (!last || last->current + num > last->last) 00119 { 00120 if (last && last->next) last = last -> next; 00121 else 00122 { 00123 block *next = (block *) new char [sizeof(block) + (block_size-1)*sizeof(Type)]; 00124 if (!next) { if (error_function) (*error_function)("Not enough memory!"); exit(1); } 00125 if (last) last -> next = next; 00126 else first = next; 00127 last = next; 00128 last -> current = & ( last -> data[0] ); 00129 last -> last = last -> current + block_size; 00130 last -> next = NULL; 00131 } 00132 } 00133 00134 t = last -> current; 00135 last -> current += num; 00136 return t; 00137 }
void Block< Type >::Reset | ( | ) | [inline] |
Type* Block< Type >::ScanFirst | ( | ) | [inline] |
Definition at line 140 of file block.h.
00141 { 00142 for (scan_current_block=first; scan_current_block; scan_current_block = scan_current_block->next) 00143 { 00144 scan_current_data = & ( scan_current_block -> data[0] ); 00145 if (scan_current_data < scan_current_block -> current) return scan_current_data ++; 00146 } 00147 return NULL; 00148 }
Type* Block< Type >::ScanNext | ( | ) | [inline] |
Definition at line 153 of file block.h.
00154 { 00155 while (scan_current_data >= scan_current_block -> current) 00156 { 00157 scan_current_block = scan_current_block -> next; 00158 if (!scan_current_block) return NULL; 00159 scan_current_data = & ( scan_current_block -> data[0] ); 00160 } 00161 return scan_current_data ++; 00162 }
int Block< Type >::block_size [private] |
void(* Block< Type >::error_function)(char *) [private] |
block* Block< Type >::scan_current_block [private] |
Type* Block< Type >::scan_current_data [private] |